import pandas as pd
from pyecharts.charts import Line, Page
import pyecharts.options as opts
from pandas.core.frame import DataFrame


def get_line_chart(x_data: list, y_tuples: list[tuple], title: str) -> Line:
    line = Line()
    line.add_xaxis([str(data) for data in x_data])
    for y_tuple in y_tuples:
        line.add_yaxis(series_name=y_tuple[0], y_axis=y_tuple[1], label_opts=opts.LabelOpts(is_show=False),
                       is_smooth=True)
    line.set_global_opts(title_opts=opts.TitleOpts(title=title))
    return line


def get_chart_html(csv_file: str = './csv/hot_top_500.csv'):
    df1 = pd.read_csv(csv_file)

    x_arr = [str(i) for i in range(1, 501)]
    like_y_arr = [like_num for like_num in df1['illust_like_cnt']]

    collect_y_arr = [like_num for like_num in df1['illust_collect_cnt']]

    print(df1['illust_collect_cnt'])
    page = Page(layout=Page.SimplePageLayout)
    line_chart = get_line_chart(x_arr, [
        ('点赞数', like_y_arr),
        ('收藏数', collect_y_arr)
    ], '热度榜前500名点赞数与收藏数的变化情况')
    page.add(line_chart)

    page.render('./ygy_line_chart.html')
